package runesim.testing;
import static java.lang.Math.*;
public class XPFormulator {
	
	public static final double[] levelXP = new double[100];
	
	static {
		double points = 0;
		double output = 0;
		for(int lvl = 0; lvl < 100; lvl++) {
			points += Math.floor(lvl + 300 * Math.pow(2, lvl / 7.));
			levelXP[lvl] = output;
			output = floor(points / 4);
		}
		System.out.println("Level XP table loaded");
	}
	
	public static int getLevelForXP(double xp) {
		if(xp >= 13034431)
			return 99; // Avoid exceptions here
		for(int i = 0; i < 99; i++) {
			if(xp >= levelXP[i] && xp <= levelXP[i + 1] - 1) {
				if(xp < 83)
					return 1;
				else
					return i;
			} else
				continue;
		}
		return -1;
	}
	
	public static double getXPForLevel(int level) throws IllegalArgumentException {
		if(level < 0 || level > 99)
			throw new IllegalArgumentException("value exceeds 99 or is lower than 0"); // Precautions
		if(level == 1)
			level = 0;
		return levelXP[level];
	}
}